package com.example.elysiumease.controller;

import com.example.elysiumease.mapper.SoulMapper;
import com.example.elysiumease.mapper.SoulSinMapper;
import com.example.elysiumease.model.SinStat;
import com.example.elysiumease.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/reports")
public class ReportController {

    //postman测试完成
    @Autowired
    private SoulMapper soulMapper;

    @Autowired
    private SoulSinMapper soulSinMapper;

    /**
     * 灵魂状态分布统计
     * @return 示例响应：{"PENDING": 15, "JUDGING": 3, "JUDGED": 42}
     */
    @GetMapping("/soul-status")
    public ResponseResult<List<Map<String, Object>>> getSoulStatusDistribution() {
        return ResponseResult.success(soulMapper.countByStatus());
    }

    /**
     * 罪行类型排行榜
     * @param days 统计最近天数（默认30天）
     * @return 示例响应：[{
     *     "sinName": "暴食",
     *     "totalCount": 156,
     *     "totalImpact": 312.0
     * },...]
     */
    @GetMapping("/sin-ranking")
    public ResponseResult<List<SinStat>> getSinRanking(
            @RequestParam(defaultValue = "30") int days) {
        if (days < 1) {
            days = 30; // 确保最小统计1天
        }
        return ResponseResult.success(soulSinMapper.getSinStatistics(days));
    }
}